<?php

namespace common\modules\article\models\backend;

use common\widgets\ActiveForm;
use common\widgets\Form;
use Yii;

/**
 * This is the form model class for model "Site".
 */
class SiteForm extends Site
{

    /**
     * @inheritdoc
     */
    public $isNewRecord;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return parent::rules();
    }

    const SCENARIO_CREATE = 'admin-create';
    const SCENARIO_UPDATE = 'admin-update';

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        return [
            'admin-create' => ['id', 'name', 'domain', 'description', 'status', 'created_at', 'updated_at', 'created_by', 'updated_by'],
            'admin-update' => ['id', 'name', 'domain', 'description', 'status', 'created_at', 'updated_at', 'created_by', 'updated_by'],
        ];
    }

    /**
     * 返回当前表单的名称
     *
     * @return string
     */
    public function classLabelName()
    {
        return Yii::t('backend/article', 'Site Form');
    }

    /**
     * 列表定义
     *
     * @param ActiveForm|Form $form
     * @param                 $model SiteForm
     * @param mixed           $extra
     * @return array
     * @throws \yii\web\ServerErrorHttpException
     */
    public function formRows(&$form, $model, $extra)
    {
        return [
            [
                'columns'    => 2,
                'attributes' => [

                    'id' => [
                        'type'    => Form::INPUT_TEXT,
                        'options' => ['disabled' => true],
                    ],

                    'name' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'domain' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'status' => [
                        'type' => Form::INPUT_WIDGET,
                        'widgetClass' => Form::SELECT2_WIDGET_CLASS,
                        'options' => [
                            'options'       => [
                                'placeholder' => Yii::t('backend/article', 'Select site status'),
                            ],
                            'pluginOptions' => [
                                'width' => '100%',
                            ],
                            'data' => self::statusArray()
                        ],
                    ],
                ],
            ],

            [
                'columns'    => 1,
                'attributes' => [
                    'description' => [
                        'type' => Form::INPUT_TEXTAREA,
                    ],
                ],
            ],

            [
                'columns'    => 2,
                'attributes' => [

                    'created_at' => [
                        'type' => Form::INPUT_STATIC,
                    ],

                    'updated_at' => [
                        'type' => Form::INPUT_STATIC,
                    ],
                ],
            ],
        ];
    }

}
